<?php

namespace app\model\content;

use app\base\BaseModel;
use think\model\concern\SoftDelete;

class ContentTypeModel extends BaseModel
{
    use SoftDelete;

    protected $name = 'content_type';



    /**
     * 范围查询-keyword
     * @param $query
     * @param $keyword
     */
    public function scopeKeyword($query, $keyword)
    {
        if (!empty($keyword)) {
            $query->whereLike('name', "%$keyword%");
        }
    }

    /**
     * 获取分页列表
     * @param $map
     * @param $keyword
     * @param $current_page
     * @param $list_rows
     * @param string $field
     * @return array
     */
    public function getPageData($map, $keyword = "", $current_page, $list_rows)
    {
        $dataList = $this
            ->keyword($keyword)
            ->where($map)
            ->order('sort', 'desc')
            ->paginate(['page' => $current_page, 'list_rows' => $list_rows], false);
        $current = $dataList->currentPage();
        $total = $dataList->total();
        $limit = $dataList->listRows();
        $ret = ['total' => $total, 'current' => $current, 'limit' => $limit, 'dataList' => $dataList->items()];
        return $ret;
    }
}
